<?php
namespace app\avikcm\controller;
use app\avikcm\model\CourseCategory as ModelCourseCategory;

class CourseCategory extends Common
{
   
    //分类列表
    public function list(){
        if(request()->isPost()){
            $list = ModelCourseCategory::all();
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
        }
        return view();
    }

    //删除
    public function del(){
        ModelCourseCategory::where('id', input('id'))->delete();
        return $result = ['code'=>1,'msg'=>'删除成功!'];
    }

    //添加
    public function add(){
        if(request()->isPost()){
            $data=input('post.');
            $data['create_time']= date('Y-m-d H:i:s');
            ModelCourseCategory::create($data);
            $result['msg'] = '添加成功!';
            $result['url'] = url('list');
            $result['code'] = 1;
            return $result;
        }else{
            $this->assign('title','添加课程分类');
            $this->assign('info','null');
            return $this->fetch('form');
        }
    }
    //修改
    public function edit(){
        if(request()->isPost()) {
            $data=input('post.');
            $data['create_time'] = date('Y-m-d H:i:s');
            $where['id'] = $data['id'];
            ModelCourseCategory::update($data,$where);
            $result = ['code'=>1,'msg'=> '课程分类修改成功!','url'=>url('list')];
            return $result;
        }else{
            $id = input('id');
            $info = ModelCourseCategory::get(['id'=>$id]);
            $this->assign('info', json_encode($info,true));
            $this->assign('title', '编辑课程分类');
            return $this->fetch('form');
        }
    }
}